/*
 * @Description  : 借阅单
 * @Author       : zhao
 * @Date         : 2022-07-07 11:21:03
 * @LastEditors  : zhao
 * @LastEditTime : 2023-02-02 13:51:47
 */

import {
    GetAssignment,
    GetIntroductionLetter,
    DownloadFormDetailExcel,
    BSDownLoadApplicationTable,
    UpdateBtnBorrowingForm,
    AddBorrowingForm,
    GetBorrowingForm,
    CSGetBorrowingFormDetails,
    GetFileNumber,
    UpdateBorrowingFormDetails,
    BSBorrowingFormRevoke,
    BSBorrowingFormDelete
} from '@/api/BorrowingForm'
import { MessageBox, Message } from 'element-ui'
const state = {
    previewType: {

    }
}

const mutations = {


}

const actions = {
    //加入借阅单
    addBorrowingForm({ commit }, data) {
        return new Promise((resolve, reject) => {
            AddBorrowingForm(data).then(res => {
                resolve(res)
            }).catch(error => {

                reject(error)
            })
        })
    },
    //获取借阅单列表
    getBorrowingForm({ commit }, data) {
        return new Promise((resolve, reject) => {
            GetBorrowingForm(data).then(res => {
                resolve(res)
            }).catch(error => {

                reject(error)
            })
        })
    },
    //获取借阅单详情
    getBorrowingFormDetails({ commit }, data) {

        return new Promise((resolve, reject) => {
            CSGetBorrowingFormDetails(data).then(res => {
                resolve(res)
            }).catch(error => {

                reject(error)
            })
        })
    },
    //获取文件数
    getFileNumber({ commit }, data) {
        return new Promise((resolve, reject) => {
            GetFileNumber(data).then(res => {
                resolve(res)
            }).catch(error => {

                reject(error)
            })
        })
    },
    //删除驳回借阅单
    updateBorrowingFormDetails({ commit }, data) {
        return new Promise((resolve, reject) => {
            UpdateBorrowingFormDetails(data).then(res => {
                resolve(res)
            }).catch(error => {

                reject(error)
            })
        })
    },
    //提交驳回借阅单
    updateBtnBorrowingForm({ commit }, data) {
        return new Promise((resolve, reject) => {
            UpdateBtnBorrowingForm(data).then(res => {
                resolve(res)
            }).catch(error => {

                reject(error)
            })
        })
    },
    //获取介绍信，任务书
    getServeFile({ commit }, data) {
        return new Promise((resolve, reject) => {
            if (data.url == "IntroductionLetter") {

                GetIntroductionLetter(data.data).then(res => {
                    resolve(res)
                }).catch(error => {

                    reject(error)
                })
            }
            if (data.url == "Assignment") {
                GetAssignment(data.data).then(res => {
                    resolve(res)
                }).catch(error => {

                    reject(error)
                })
            }
        })
    },
    //打印借阅单详情---生成excel
    DownloadFormDetailExcel({ commit }, data) {
        return new Promise((resolve, reject) => {
            DownloadFormDetailExcel(data).then(res => {
                resolve(res)
            }).catch(error => {

                reject(error)
            })
        })
    },
    //BS下载地质资料使用申请表
    BSDownLoadApplicationTable({ commit }, data) {
        return new Promise((resolve, reject) => {
            BSDownLoadApplicationTable(data).then(res => {
                resolve(res)
            }).catch(error => {

                reject(error)
            })
        })
    },
    //用户删除订单，（只能删除已驳回，已撤回，已完成状态的订单
    BSBorrowingFormDelete({ commit }, data) {
        return new Promise((resolve, reject) => {
            BSBorrowingFormDelete(data).then(res => {
                if (res.code == 200) {

                    Message.success(res.msg || "删除订单成功")
                    resolve(res)
                } else {
                    Message.error(res.msg || "删除订单失败")
                }
            }).catch(error => {

                reject(error)
            })
        })
    },
    //用户自主撤销借阅单,只能撤销已提交状态的借阅单
    BSBorrowingFormRevoke({ commit }, data) {
        return new Promise((resolve, reject) => {
            BSBorrowingFormRevoke(data).then(res => {
                if (res.code == 200) {
                    Message.success(res.msg || "撤销订单成功")
                    resolve(res)
                } else {
                    Message.error(res.msg || "撤销订单失败")
                }
            }).catch(error => {

                reject(error)
            })
        })
    },

}
const getters = {

}
export default {
    namespaced: true,
    state,
    mutations,
    getters,
    actions
}
